Skip to content

Endpoint for pretty print migration plan #3137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: shub/moduledef-pretty-print
Choose a base branch
from

Conversation

Shubham8287
Copy link
Contributor

Description of Changes

Adds endpoint for for pretty printing migration plan.
It also changes current publish endpoint to optionally provide MigrationToken and MigrationPolicy to allow migration with breaking clients.

API and ABI breaking changes

Backward compatible change to existing API and new Api

Expected complexity level and risk

2

Testing

  • Existing smoketest should cover changes for publish endpoint.
  • For pretty print endpoint, smoketests can be written only after cli changes.

@Shubham8287 Shubham8287 requested review from gefjon and Centril August 7, 2025 19:22
@Shubham8287 Shubham8287 force-pushed the shub/pretty-endpint branch from 4fca9d9 to 68d0045 Compare August 7, 2025 19:46
@bfops bfops added the release-any To be landed in any release window label Aug 11, 2025
}

impl MigrationToken {
pub fn hash(&self) -> spacetimedb_lib::Hash {
Copy link
Contributor Author

@Shubham8287 Shubham8287 Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not included any secret in token generation which means, anyone with enough intent could recreate the token generation logic and bypass it. Considering this token act as UX safegaurd and not for security. I feel, this acceptable and we don't have to worry about managing a secret.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but please add a comment to this effect in the code.

@Shubham8287
Copy link
Contributor Author

CI is breaking because of base branch.

@@ -835,6 +962,7 @@ where

axum::Router::new()
.route("/", self.root_post)
.route("/print-plan/:name_or_identity", self.print_migration_plan)
Copy link
Contributor Author

@Shubham8287 Shubham8287 Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used "print-plan" as endpoint instead of "pre-publish" as former sounds more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. pre-publish clearly relates this operation to publishing, whereas print-plan could do pretty much anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most notably, I would confuse print-plan with displaying a query plan for a given SQL query.

@@ -469,6 +474,9 @@ pub struct PublishDatabaseQueryParams {
#[serde(default)]
clear: bool,
num_replicas: Option<usize>,
// `Hash` of `MigrationToken` to be checked if `MigrationPolicy::BreakClients` is set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// `Hash` of `MigrationToken` to be checked if `MigrationPolicy::BreakClients` is set.
/// `Hash` of `MigrationToken` to be checked if `MigrationPolicy::BreakClients` is set.
///
/// Users obtain such a hash from [`print_migration_plan`]
/// via the `/database/:name_or_identity/pre-publish POST` route.
/// This is a safeguard to require explicit approval for updates which will break clients.

@@ -835,6 +962,7 @@ where

axum::Router::new()
.route("/", self.root_post)
.route("/print-plan/:name_or_identity", self.print_migration_plan)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most notably, I would confuse print-plan with displaying a query plan for a given SQL query.

@@ -469,6 +474,9 @@ pub struct PublishDatabaseQueryParams {
#[serde(default)]
clear: bool,
num_replicas: Option<usize>,
// `Hash` of `MigrationToken` to be checked if `MigrationPolicy::BreakClients` is set.
token: Option<spacetimedb_lib::Hash>,
policy: Option<MigrationPolicy>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to default this to Compatible rather than wrapping it in Option.


#[derive(serde::Deserialize)]
pub struct PrintPlanQueryParams {
style: Option<PrettyPrintStyle>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, defaulting would be preferred over Option.


if database.owner_identity != auth.identity {
return Err((
StatusCode::BAD_REQUEST,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
StatusCode::BAD_REQUEST,
StatusCode::UNAUTHORIZED,

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MigrationPolicy {
Compatible,
BreakClients(spacetimedb_lib::Hash),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add doc comment describing this value and where to obtain it, like in the client-api crate.

}

impl MigrationToken {
pub fn hash(&self) -> spacetimedb_lib::Hash {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but please add a comment to this effect in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants